package indi.zhifa.recipe.bailan5.coupon.handler;

import indi.zhifa.recipe.bailan.framework.queue.bean.MsgHandlerMap;
import indi.zhifa.recipe.bailan.framework.queue.entity.MsgHandlerInfo;
import indi.zhifa.recipe.bailan.framework.queue.handler.BaseRedisMsgConsumerListener;
import indi.zhifa.recipe.bailan5.coupon.util.AppConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class CouponMsgListener extends BaseRedisMsgConsumerListener {

    private final CouponMsgHandler mCouponMsgHandler;

    @Autowired
    public CouponMsgListener( RedisTemplate<String, Object> pRedisTemplate,
                              CouponMsgHandler pCouponMsgHandler) {
        super(AppConst.COUPON_CONSUME_GROUP, pRedisTemplate);
        mCouponMsgHandler = pCouponMsgHandler;
    }

    @Override
    protected MsgHandlerMap initMsgHandlerMap() {
        MsgHandlerMap msgHandlerMap = new MsgHandlerMap() {
            @Override
            protected void init() {
                MsgHandlerInfo couponHandler = new MsgHandlerInfo();
                couponHandler.setCls(CouponMsgHandler.class);
                couponHandler.setMessageHandler(mCouponMsgHandler);
                this.msgHandlerMapData.put(AppConst.COUPON_USE,couponHandler);
            }
        };
        return msgHandlerMap;
    }
}
